package com.example.yunhailutong.zhongtan.Adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.example.yunhailutong.zhongtan.fragment.BaseFragment;
import com.example.yunhailutong.zhongtan.fragment.FragmentGongYing;
import com.example.yunhailutong.zhongtan.fragment.FragmentList;
import com.example.yunhailutong.zhongtan.fragment.FragmentXuQiu;
import com.example.yunhailutong.zhongtan.fragment.MineFragment;

import java.util.ArrayList;

/**
 * Created by yunhailutong on 2018/7/23.
 */

public class DingDanBaseFragmentPagerAdapter extends FragmentPagerAdapter {
    public DingDanBaseFragmentPagerAdapter(FragmentManager fm, String[] titles) {
        super(fm);
        mFragmentList = new ArrayList<>();
        this.TITLES = titles;
        for (int i = 0; i < TITLES.length; i++) {
            mFragmentList.add(instanceFragment(i));
        }
    }

    private ArrayList<BaseFragment> mFragmentList;

    private  String[] TITLES;

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    private BaseFragment instanceFragment(int position) {
        BaseFragment fragment = null;
        switch (position) {
            case 0:
                fragment = new FragmentList("0");
                break;
            case 1:
                fragment = new FragmentList("1");
                break;
            case 2:
                fragment = new FragmentList("2");
                break;
            case 3:
                fragment = new FragmentList("3");
                break;
            case 4:
                fragment = new FragmentList("4");
                break;
        }
        return fragment;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return TITLES[position];
    }

    @Override
    public int getCount() {
        return TITLES.length;
    }
}